
-- ./mongodump -h 192.168.30.21 -uispc -pispc -d ispc -o /Users/Julia/tdd

-- ./mongorestore -h 192.168.30.21 -uispc -pispc --authenticationDatabase ispc  -d ispc  /Users/Julia/tdd/ispc

-- mongodb
var tables = db.getCollectionNames();
for(var i=0;i<tables.length;i++){
        if(tables[i]!='system.js' && tables[i] != "testItemName" && tables[i] != "testStation") {
            var prefix = tables[i].substring(0, tables[i].lastIndexOf("_") + 1) + "spc_";
            var projectId = tables[i].substring(tables[i].lastIndexOf("_") + 1, tables[i].length);
            var collectionName = prefix + projectId;
            eval("db."+tables[i]+".renameCollection('"+collectionName+"')");
        }
 };


-- postgresql
DROP FUNCTION public.updatePSGRR();
CREATE OR REPLACE FUNCTION public.updatePSGRR()
RETURNS void AS
$BODY$DECLARE
 tmp VARCHAR(512);
DECLARE ids CURSOR FOR
 SELECT id FROM t_project;
BEGIN
FOR stmt IN ids LOOP
 tmp := stmt.id;
RAISE NOTICE 'notice: %', tmp;
 EXECUTE format('INSERT INTO t_psgrr(rule, model, sigma, defaultmodelvalue, projectid, createby) VALUES ($1,$2,$3,$4,$5,$6);')
    using '[10,20,30]','NORMAL', '6.0', '[10,3,3]', stmt.id ,'';
END LOOP;
RAISE NOTICE 'finished .....';
END;$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION public.updatePSGRR()
OWNER TO ispc;

select updatePSGRR();

DROP FUNCTION public.updatePSGRR();